<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //封装type
        //typeof([]) --- array

        function type(arg){
            var toS = Object.prototype.toString;
            var strObj = "[object Object]";
            var strArr = "[object Array]";
            var strString = "[object String]";
            var strNumber = "[object Number]";
            var strFun = "[object Function]";
            var strNull = "[object Null]";
            var strUnd = "[object Undefined]";
            var val = toS.call(arg);
            switch(val){
                case strObj :
                console.log('object');
                break;

                case strArr :
                console.log('array');
                break;

                case strFun :
                console.log('function');
                break;
                
                case strString :
                if(typeof(arg) == "string"){
                    console.log("string");
                }else{
                    console.log("string object");
                }
                break;

                case strNumber :
                if(typeof(arg) == "number"){
                    console.log("number");
                }else{
                    console.log("number object");
                }
                break;
                
                case strNull :
                console.log("null");
                break;
                
                case strUnd :
                console.log('undefined');
                break;

                default :
                console.log("error");
            }
        }
    </script>
</body>
</html>